﻿#include <opencv2\opencv.hpp>
#include "FinderCake.hpp"
#include <fstream>
#include "FinderScrew.hpp"

#include "Stroke.hpp"

static void writect(const std::vector<cv::Point> &cnt, std::string fp = "ct.txt")
{
	std::ofstream ofs(fp.c_str());

	if (ofs)
	{
		for (size_t i = 0;i < cnt.size();i++)
			ofs << cnt[i] << '\n';

		ofs.close();
	}
}



int main()
{

	//cv::Mat m = cv::imread("C:\\Users\\jhanbin\\Pictures\\58002109_p0.png");

	//cv::Mat fm(1080, 1920, CV_8UC3, cv::Scalar::all(255));
	//m.copyTo(fm(cv::Rect(460, 40, m.cols, m.rows)));


	//cv::cvtColor(fm, fm, CV_BGR2RGB);
	////cv::imshow("fm", fm);
	////cv::waitKey();

	//cv::VideoWriter vw("test.avi", CV_FOURCC('Y', 'V', '1', '2'), 15, fm.size());

	//for (int i = 0; i < 300; i++)
	//{
	//	vw.write(fm);
	//}
	//vw.release();

	cv::Mat m = cv::imread("C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg", 0);

	cv::Mat mf;
	m.convertTo(mf, CV_64F);
	//mf /= 255;
	//cv::imshow("mf", mf);

	cv::Mat k1 = (cv::Mat_<double>(3, 3) << 
		-1, -2, -1, 
		0, 0, 0,
		1, 2, 1);
	cv::Mat k2 = (cv::Mat_<double>(3, 3) << 
		-1, 0, 1, 
		-2, 0, 2,
		-1, 0, 1);

	cv::Mat mo[2];

	cv::filter2D(mf, mo[0], -1, k1);
	cv::filter2D(mf, mo[1], -1, k2);

	cv::Mat msq;

	cv::sqrt(mo[0].mul(mo[0]) + mo[1].mul(mo[1]), msq);

	msq = 255 - msq;

	cv::Mat msq8;
	msq.convertTo(msq8, CV_8U);

	cv::imshow("msq8", msq8);


	//cv::Mat m = cv::imread("lscm.png", 0);

	//cv::Mat bw = (m < 128);
		
	//cv::imshow("bw", bw);
	cv::waitKey();
	//GetStroke(bw);

	
	FinderCake f;

	//PipeA pa;
	//pa.SetPos(f.idlepos);

	//f.ManualPath();

	//f.AutoPath();

	//f.CheckH();

	//f.ReCalib();

	//Find::Calib();

	//FinderScrew fs;

	//fs.ManualPath(1);

	//fs.Calibrate();

	//fs.CalibDesk();



	return 0;
}
